package main;

import Bean.UserInfoBean;
import utils.DBUtils;

import java.util.Scanner;

public class UserManage {
    static Scanner sc = new Scanner(System.in);
    static DBUtils dbUtils;
    public static void manageUser(UserInfoBean user) {
        System.out.println("\n\n\n");
        System.out.println("---------这里是用户管理界面---------");
        System.out.println("姓名：" + user.getName());

        userManageBreak:
        while (true) {
            System.out.println("请选择你要做什么:");
            System.out.println("1 - 修改用户名 ");
            System.out.println("2 - 修改用户密码 ");
            System.out.println("3 - 修改支付密码");
            System.out.println("4 - 返回上一级");

            switch (sc.nextInt()) {
                case 1:
                    changeUserName(user);
                    break userManageBreak;
                case 2:
                    changeUserPassword(user);
                    break userManageBreak;
                case 3:
                    changeUserPayPassword(user);
                    break userManageBreak;
                case 4:
                    User.mainScreen(user);
                    break userManageBreak;
                default:
                    System.out.println("不要胡乱输入哦！！！");
                    break;
            }
        }
    }

    public static void changeUserName(UserInfoBean user){
        String pw , newName = "";
        for(int i = 0 ; i < 3 ; i ++) {
            System.out.println("请输入你的登录密码：");
            pw = sc.next();
            if(pw.equals(user.getPassword())){
                System.out.println("请输入你要修改的用户名：");
                newName = sc.next();
                dbUtils.updateUser("Name" , newName , user.getID());
                user.setName(newName);
                manageUser(user);
                break;
            }
            System.out.println("密码错误，你还有 " + (3 - i - 1) +" 次机会");
        }

        System.out.println("密码输入不对，下去沉淀沉淀吧");
    }

    public static void changeUserPassword(UserInfoBean user){
        String pw , newPw = "";
        for(int i = 0 ; i < 3 ; i ++) {
            System.out.println("请输入你的原登录密码：");
            pw = sc.next();
            if(pw.equals(user.getPassword())){
                System.out.println("请输入你要修改的密码：");
                newPw = sc.next();
                dbUtils.updateUser("Password" , newPw , user.getID());
                user.setPassword(newPw);
                manageUser(user);
                break;
            }
            System.out.println("密码错误，你还有 " + (3 - i - 1) +" 次机会");
        }

        System.out.println("密码输入不对，下去沉淀沉淀吧");

    }

    public static void changeUserPayPassword(UserInfoBean user){
        String ppw , newPpw = "";
        for(int i = 0 ; i < 3 ; i ++) {
            System.out.println("请输入你的原支付密码：");
            ppw = sc.next();
            if(ppw.equals(user.getPwd())){
                System.out.println("请输入你要修改的支付密码：");
                newPpw = sc.next();
                dbUtils.updateUser("Pwd" , newPpw , user.getID());
                user.setPwd(newPpw);
                manageUser(user);
                break;
            }
            System.out.println("密码错误，你还有 " + (3 - i - 1) +" 次机会");
        }

        System.out.println("密码输入不对，下去沉淀沉淀吧");

    }



}
